package com.manlost.biz.baby.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.manlost.biz.baby.BabyService;
import com.manlost.biz.baby.impl.dao.interfaces.BabyDAO;
import com.manlost.biz.baby.impl.dao.interfaces.BabyDraftDAO;
import com.manlost.biz.baby.model.dataobject.Baby;
import com.manlost.biz.baby.model.dataobject.BabyDraft;
import com.manlost.biz.baby.query.BabyQuery;
import com.manlost.biz.common.ibatis.PageQueryList;

/**
 * 类BabyServiceImpl
 * 
 * @author wqq
 * 
 */
@Service
public class BabyServiceImpl implements BabyService {
	@Autowired
	private BabyDAO babyDAO;
	@Autowired
	private BabyDraftDAO babyDraftDAO;

	@Override
	public PageQueryList<Baby> listBabys(BabyQuery query) {
		return babyDAO.findListByQuery(query);
	}

	@Override
	public Baby getOneBabyById(Long babyId) {
		if(babyId==null||babyId<=0){
			throw new IllegalArgumentException();
		}
		return babyDAO.findOneByPrimaryKey(babyId);
	}

	@Override
	public List<Baby> getBabysByIds(List<Long> ids) {
		return babyDAO.listBabyByIds(ids);
	}

	@Override
	public boolean insetOneBaby(Baby baby) {
		return babyDAO.insertOne(baby)>0?true:false;
	}
	
	@Override
	public boolean insetOneBabyDraft(BabyDraft baby) {
		return babyDraftDAO.insertOne(baby)>0?true:false;
	}

	@Override
	public Long inserBabies(List<Baby> babies) {
		// TODO Auto-generated method stub
		return babyDAO.insertBabies(babies);
	}

	@Override
	public Long inserBabyDrafts(List<BabyDraft> babyDrafts) {
		// TODO Auto-generated method stub
		//return babyDraftDAO.insertBabyDrafts(babyDrafts);
		long count=0;
		for(BabyDraft draft:babyDrafts){
			count+=insetOneBabyDraft(draft)==true?1:0;
		}
		return count;
	}
}
